package com.marketlive.biz.session.context;

/*
 * UpdateCustomerCommand.java
 *
 * Created on July 30, 2001, 1:37 PM
 */

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.marketlive.biz.session.context.ICommerceSession;

import com.marketlive.app.b2c.account.LoginAction;

/**
 * @author elena
 */
public class UpdateCustomerCommand extends CommerceSessionCommand {
    private static Log logger = LogFactory.getLog(UpdateCustomerCommand.class);

    /**
     * Creates new CommerceSessionFinalCommand
     */
    public UpdateCustomerCommand() {
        super();
        name_ = "Update Customer";
    }

    /**
     * Updates the CUSTOMER table with session info: total time the customer spent on the site and total
     * number of sessions he initiated.
     */
    public int run(ICommerceSession session) throws Exception {
        try {
            // update status
            status_ = SUCCESS;
            
            // update Customer object with session data
            //todo:huw
            /*
            ICustomer customer = session.getCustomer();
            long sessionTime = session.getLastRequestStartTime() - session.getSessionSummary().getStartTime().getTime();
            if (sessionTime < 0) sessionTime = new Date().getTime() - session.getStartTime();
            customer.setTotalSiteTime(sessionTime); // add this session time to the total time on site
            customer.setTotalSessions(1);// add one to the total session count
            //customer.setLastTimeOnSite(new Date());
            */
            // update customer record in the database
            // todo: make sure changes to customer are written out
            // customer.dbUpdate(null);
        } catch (Exception e) {
            status_ = FATAL_ERROR;
            logger.error(" Error running UpdateCustomerComamnd", e);
            throw new Exception(e.getMessage());
        } finally {
            logger.info("UpdateCustomerCommand exited with status " + status_);
            return status_;
        }
    }
}
